<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/5
 * Time: 11:11
 */

namespace app\admin\model;


use think\Model;

class Pages extends Model
{
    public function category()
    {
        return $this->belongsTo('Category');
    }

    public function edit($data)
    {
        unset($data['thumb_del']);
        $this->allowField(true)->update($data);
        return $this;
    }

    public function del($where)
    {
        $info = $this->field('thumb')->where($where)->find();
        $this->where($where)->delete();
        if (!empty($info['thumb']))
        {
            $path = './public/'.$info['thumb'];
            if (file_exists($path))
            {
                @unlink($path);
            }
        }
        return $this;
    }
}